import { login } from "../api/user";
import { setCookie } from "./useCookie";
import { tokenKey } from "../config/cache-keys";
function useLogin() {
  return new Promise((resolve, reject) => {
    uni.login({
      success(res) {
        if (res.code) {
          //发起网络请求
          login({ code: res.code }).then(({ data }) => {
            setCookie(tokenKey, data);
            resolve();
          });
        } else {
          console.log("登录失败！" + res.errMsg);
          reject();
        }
      },
    });
  });
}

export default useLogin;
